<template>
  <div class="cell_group">
    <div class="cell">
      <div class="title">
        {{config.attrName}}
      </div>
      <div class="input_icon">
        <input :class="{'isWrong':!noWrong}" type="number" oninput='if(value.length > 30)value = value.slice(0, 30)' :placeholder="'请输入'+config.attrName" v-model="config.value" @blur="changeName('blur')" @focus="changeName('focus')">
        <span class="unit">元</span>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "price",
  props: {
    config: {
      type: Object,
      required: true
    },
    parentIndex: Number,
    itemIndex: Number
  },
  data() {
    return {
      noWrong: true
    };
  },
  created() {
    this.config.value = this.config.value ? this.config.value : "";
  },
  methods: {
    onMaxlength() {},
    changeName(e) {
      if (e === "focus") {
        this.noWrong = true;
      } else {
        // console.log('正则--》',new RegExp(this.config.patternCondition).test(this.config.value))
        if (this.config.patternCondition) {
          this.noWrong = new RegExp(this.config.patternCondition).test(
            this.config.value
          );
        }
        this.config.noWrong = this.noWrong;
        this.$emit(
          "changeValue",
          this.parentIndex,
          this.itemIndex,
          this.config
        );
      }
    }
  }
};
</script>
<style lang="less">
</style>

